package com.nowcoder.community.config;

import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

/**
 * <p>Title: Esconfig</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2022/8/22 19:51
 */
@Configuration
public class Esconfig {

    @Value("${spring.elasticsearch.uris}")
    private String esUrl  ;

    @Bean
    RestHighLevelClient client(){
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(esUrl)
                .build() ;
        return RestClients.create(clientConfiguration).rest() ;
    }
}
